// 导入组件
import Vue from 'vue';
import VueRouter from 'vue-router';
//导入页面
import { login, index, dataStatistics,error404 ,student,course,admin,project,videoCourse,videoList} from '@/views'
// 启用路由
Vue.use(VueRouter);
// 解决通过路由进行当前页面点击报错问题
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
};
// 导出路由 
const router = new VueRouter({
    routes: [{
        path: '/',
        name: '',
        component: login,
        hidden: true,
        meta: {
            requireAuth: false
        }
    }, {
        path: '*',
        name: 'error404',
        component: error404,
        hidden: true,
        meta: {
            requireAuth: false
        }
    }, {
        path: '/login',
        name: 'login',
        component: login,
        hidden: true,
        meta: {
            requireAuth: false
        }
    }, {
        path: '/index',
        name: 'index',
        component: index,
        iconCls: 'el-icon-tickets',
        children: [
            {
                path: '/dataStatistics',
                name: 'dataStatistics',
                component: dataStatistics,
                meta: {
                    requireAuth: true
                }
            },{
                path: '/student',
                name: 'student',
                component: student,
                meta: {
                    requireAuth: true
                }
            },{
                path: '/course',
                name: 'course',
                component: course,
                meta: {
                    requireAuth: true
                }
            },{
                path: '/project',
                name: 'project',
                component: project,
                meta: {
                    requireAuth: true
                }
            },{
                path: '/admin',
                name: 'admin',
                component: admin,
                meta: {
                    requireAuth: true
                }
            },{
                path: '/videoCourse',
                name: 'videoCourse',
                component: videoCourse,
                meta: {
                    requireAuth: true
                }
            },{
                path: '/videoList',
                name: 'videoList',
                component: videoList,
                meta: {
                    requireAuth: true
                }
            }
									
        ]
    }]
})
export default router

// router.beforeEach((to, from, next) => {
//     if (to.meta.requireAuth) {       //页面用不用判断是否登录
//         if (JSON.parse(sessionStorage.getItem('json'))) { // 如果已经有登录状态的话，走下一个页面
//             next();
//         } else {
//             if (to.path === '/login') { // 如果是登录页面的话，直接next()
//                 next();
//             } else { // 否则 跳转到登录页面
//                 next({
//                     path: '/login'
//                 });
//             }
//         }
//     } else {
//         next();
//     }

// })